home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-02-13 | 5.0 KB | 187 lines | [TEXT/PJMM] |
- UNIT Windows;
-
- INTERFACE
-
- USES
- MacPrint, MyGlobals, DumpTPrint;
-
- PROCEDURE CheckWindowMode;
- PROCEDURE CloseAWindow;
- PROCEDURE DialogueDeactivate;
- PROCEDURE DrawWindow;
- PROCEDURE MyActivate;
- PROCEDURE OpenAWindow;
-
- IMPLEMENTATION
-
- { Windows segment }
-
- {-----------Update menus based on windows---------}
- PROCEDURE CheckWindowMode;
- VAR
- newmode : MyWindMode;
- fileset : SET OF 1..lastFileItem;
- item : INTEGER;
- BEGIN { This routine enable/disables menu items based on window mode }
- myPeek := WindowPeek(FrontWindow);
- IF myPeek = NIL THEN
- newmode := NullMode { no windows open }
- ELSE IF myPeek^.windowKind = MyDocument THEN
- newmode := OpenMode { document window on top }
- ELSE
- newmode := DAMode; { assume must be D.A. on top }
- IF newmode <> currWMode THEN { Must change menus }
- BEGIN
- CASE newmode OF
- NullMode : { No windows open }
- fileset := [newItem, quitItem];
- OpenMode : { One window open and on top }
- fileset := [closeItem, stlItem, jobItem, setupItem, printItem, quitItem];
- DAMode : { DA on top }
- fileset := [closeItem, quitItem];
- OTHERWISE
- BEGIN
- END;
- END; {CASE newmode}
- FOR item := 1 TO lastFileItem DO
- IF item IN fileset THEN
- EnableItem(myMenus[fileMenu], item)
- ELSE
- DisableItem(myMenus[fileMenu], item);
-
- IF newmode = DAMode THEN
- EnableItem(myMenus[editMenu], 0)
- ELSE
- DisableItem(myMenus[editMenu], 0);
-
- DrawMenuBar; { menu dimming must be updated }
- currWMode := newmode;
- END; {IF newmode <> currWMode}
- END; {CheckWindowMode}
-
- {----------Close the front window----------}
- PROCEDURE CloseAWindow;
- BEGIN
- { This routine closes an application (or DA) window, either after}
- { • clicking go-away box }
- { • selecting "Close" in File menu }
- myPeek := WindowPeek(FrontWindow);
- IF myPeek^.windowKind = myDocument THEN
- BEGIN
- wdh := WindowDataHandle(GetWRefCon(WindowPtr(myPeek)));
- ph := wdh^^.theTHP;
- DisposHandle(Handle(ph));
- TEDispose(hTE);
- hTE := NIL;
- DisposHandle(Handle(wdh));
- DisposeWindow(myWindow);
- END {myDocument window}
- ELSE { Must be a DA }
- CloseDeskAcc(myPeek^.windowKind)
- END; {CloseAWindow}
-
- {-----------------Deactivate before dialog----------}
- {Deactivate the top window if we're about to put up a dialog}
- PROCEDURE DialogueDeactivate;
- VAR
- temprect : Rect;
- BEGIN
- SetCursor(arrow);
- IF hTE <> NIL THEN {for documents, only}
- TEDeactivate(hTE);
- END; {DialogueDeactivate}
-
- {---------Draw a document window----------}
- { Handles window Update Event}
- PROCEDURE DrawWindow;
- VAR
- tempport : GrafPtr;
- temprect, rectToErase : Rect;
- temppeek : WindowPeek;
- whichwindow : WindowPtr;
- temphTE : TEHandle;
- BEGIN
- whichwindow := WindowPtr(myEvent.message);
- BeginUpdate(whichwindow);
- GetPort(tempport);
- SetPort(whichwindow);
- temppeek := WindowPeek(whichwindow);
- IF temppeek^.windowKind = myDocument THEN
- BEGIN
- temprect := whichwindow^.Portrect;
- wdh := WindowDataHandle(GetWRefCon(whichwindow));
- temphTE := wdh^^.theTE;
- SetRect(temprect, -32767, -32767, 32767, 32767);
- ClipRect(temprect);
- {this only erases the window past the end of text, if any}
- WITH temphTE^^ DO
- IF nLines < (viewRect.bottom - viewRect.top + lineHeight) DIV lineHeight THEN
- BEGIN
- rectToErase := viewRect;
- rectToErase.top := (nLines) * lineHeight;
- EraseRect(rectToErase)
- END; {nLines}
- TEUpdate(whichwindow^.visRgn^^.rgnBBox, temphTE)
- END; {myDocument stuff}
- SetPort(tempport);
- EndUpdate(whichwindow)
- END; {DrawWindow}
-
- {-------------Handle (de)activate events-----------}
- PROCEDURE MyActivate;
-
- BEGIN {This activates or deactivates the current selection}
- myWindow := WindowPtr(myEvent.message);
- myPeek := WindowPeek(myWindow);
- IF myPeek^.windowKind = myDocument THEN
- BEGIN { document window }
- wdh := WindowDataHandle(GetWRefCon(myWindow));
- hTE := wdh^^.theTE;
- IF ODD(myEvent.modifiers) THEN { BitAnd(myEvent.modifiers,activeFlag)>0 }
- TEActivate(hTE) {this window is now top most}
- ELSE {this window is no longer top most}
- BEGIN
- TEDeactivate(hTE);
- hTE := NIL {a TextEdit window is no longer on top}
- END;
- END;
-
- END; {MyActivate}
-
- {-------------Create a new document window-------}
- PROCEDURE OpenAWindow;
-
- VAR
- r : Rect;
-
- BEGIN {A window is created here}
-
- myWindow := GetNewWindow(WIND_main, NIL, Pointer(-1));
- wdh := WindowDataHandle(NewHandle(SIZEOF(WindowData)));
- SetWRefCon(myWindow, ORD(wdh)); { stash pointer to TEHandle in window }
-
- SetPort(myWindow);
- myPeek := WindowPeek(myWindow);
- TextFont(myStdFont);
- TextSize(myStdSize);
- DrawChar(' ');
- SetFontLock(TRUE);
- myPeek^.windowKind := myDocument; {identifies the type of window}
-
- r := myWindow^.Portrect;
- InsetRect(r, 8, 4);
- hTE := TENew(r, r);
- wdh^^.theTE := hTE;
- hTE^^.destRect := hTE^^.viewRect;
- hTE^^.crOnly := -1; { no automatic CR }
-
- PrOpen;
- ph := THPrint(NewHandle(SIZEOF(TPrint)));
- PrintDefault(ph);
- wdh^^.theTHP := ph;
- DumpPrint('After PrintDefault(…)', ph);
- PrClose;
-
- END; {OpenAWindow}
-
- END.